#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL num[maxn],maxv1[maxn],minv1[maxn],maxv2[maxn],minv2[maxn];
char str[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n,m;cin>>n>>m;
    for(LL i=0;i<n+10;i++) num[i]=0;
    for(LL i=1;i<=n;i++) cin>>str[i];
    LL ans=0;
    maxv1[0]=minv1[1]=0;
    for(LL i=1;i<=n;i++){
        if(str[i]=='+') ans++;
        if(str[i]=='-') ans--;
        num[i]=ans;
        maxv1[i]=max(maxv1[i-1],num[i]);
        minv1[i]=min(minv1[i-1],num[i]);
    }
    ans=0;maxv2[n+1]=minv2[n+1]=0;
    for(LL i=n;i>=1;i--){
        if(str[i]=='-') ans++;
        if(str[i]=='+') ans--;
        maxv2[i]=max(maxv2[i+1],ans);
        minv2[i]=min(minv2[i+1],ans);
    }
    while(m--){
        LL l,r;cin>>l>>r;
        LL res1=-0x3f3f3f3f;LL res2=0x3f3f3f3f;
        LL p= -(num[r]-num[l-1]);
        LL k=abs(num[n]);
        if(num[n]>0) p+=k;
        else p-=k;
        res1=max(maxv1[l-1],maxv2[r+1]+p);
        res2=min(minv1[l-1],minv2[r+1]+p);
        cout<<res1-res2+1<<"\n";
    }
  }
return 0;
}
